package canglang.monitor.cases.dao;

import java.util.*;

import canglang.monitor.core.base.dao.BaseDAO;
import canglang.monitor.core.base.util.StringUtil;
import canglang.monitor.core.base.util.DateUtil;
import canglang.monitor.core.base.pagination.PaginatedListHelper;
import canglang.monitor.cases.model.CaseTwoModel;
import canglang.monitor.cases.to.SearchTwoTO;

@SuppressWarnings("unchecked")
public class CaseTwoDAO extends BaseDAO {
    public Integer addCaseTwo(CaseTwoModel caseTwoModel) {
        String sql = "addCaseTwo";
        Map map = objectToMap(caseTwoModel);
        return (Integer) getSqlMapClientTemplate().insert(sql, map);
    }

    public CaseTwoModel getCaseTwo(int caseTwoId) {
        String sql = "getCaseTwo";
        Map map = new HashMap();
        map.put("caseTwoId", caseTwoId);
        return (CaseTwoModel) getSqlMapClientTemplate().queryForObject(sql, map);
    }

    public CaseTwoModel saveCaseTwo(CaseTwoModel caseTwoModel) {
        String sql = "saveCaseTwo";
        Map map = objectToMap(caseTwoModel);
        getSqlMapClientTemplate().update(sql, map);
        return this.getCaseTwo(caseTwoModel.getCaseTwoId());
    }

    public void deleteCaseTwo(int caseTwoId) {
        String sql = "deleteCaseTwo";
        Map map = new HashMap();
        map.put("caseTwoId", caseTwoId);
        getSqlMapClientTemplate().delete(sql, map);
    }

    public Integer searchCount(SearchTwoTO searchTO) {
        Map map = new HashMap();
        map.put("deptId", searchTO.getDeptId());
        map.put("dateFrom", searchTO.getDateFrom());
        if (searchTO.getDateTo() != null) {
            map.put("dateTo", DateUtil.add(searchTO.getDateTo(), Calendar.DATE, 1));
        }
        map.put("createId", StringUtil.convertEmpty2Null(searchTO.getCreateId()));
        return (Integer) getSqlMapClientTemplate().queryForObject("searchCaseTwoCount", map);
    }

    public List searchList(PaginatedListHelper helper, SearchTwoTO searchTO) {
        Map map = new HashMap();
        map.put("deptId", searchTO.getDeptId());
        map.put("dateFrom", searchTO.getDateFrom());
        if (searchTO.getDateTo() != null) {
            map.put("dateTo", DateUtil.add(searchTO.getDateTo(), Calendar.DATE, 1));
        }
        map.put("createId", StringUtil.convertEmpty2Null(searchTO.getCreateId()));
        map = constructPaginationMap(helper, map);
        return getSqlMapClientTemplate().queryForList("searchCaseTwoList", map);
    }

     public List getCaseTwoList(SearchTwoTO searchTO) {
        Map map = new HashMap();
        int deptId = searchTO.getDeptId();
        Date dateFrom = searchTO.getDateFrom();
        Date dateTo = searchTO.getDateTo();
        map.put("deptId", deptId);
        map.put("dateFrom", dateFrom);
        if (dateTo != null) {
            map.put("dateTo", DateUtil.add(dateTo, Calendar.DATE, 1));
        }
        return getSqlMapClientTemplate().queryForList("getCaseTwoList", map);
    }

}
